package xyz.jcat.seata.example;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import xyz.jcat.generator.mybatis.Generator;
import xyz.jcat.generator.mybatis.config.DB;
import xyz.jcat.generator.mybatis.config.DbConfig;
import xyz.jcat.generator.mybatis.config.PersonalizedConfig;
import xyz.jcat.seata.example.points.PointsApplication;

import java.io.IOException;

@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = PointsApplication.class)
public class TableGenerator {

    @Autowired
    private Generator generator;

    @Test
    public void test() throws IOException {
        DbConfig dbConfig = new DbConfig();
        dbConfig.setDb(DB.MYSQL);
        generator.setDbConfig(dbConfig);
        PersonalizedConfig personalizedConfig = new PersonalizedConfig();
        personalizedConfig.setAuthor("yueyue");
        personalizedConfig.setGroup("xyz.jcat");
        personalizedConfig.setProjectName("seata.example.points");
        personalizedConfig.setDaoName("I%sDao");
        personalizedConfig.setMapperName("%sMapper");
        personalizedConfig.setPoName("%sPo");
        personalizedConfig.setPoPackage("domain.po");
        personalizedConfig.setDaoPackage("domain.dao");
        personalizedConfig.setSaveDir("E:\\workspaces\\jcat\\examples\\seata-example\\lagou-points\\src\\main\\java");
        personalizedConfig.setMapperXmlPath("E:\\workspaces\\jcat\\examples\\seata-example\\lagou-points\\src\\main\\resources\\mapper");
        personalizedConfig.setCreateDao(true);
        personalizedConfig.setCreateIService(true);
        personalizedConfig.setCreateService(false);
        personalizedConfig.setCreatePo(true);
        personalizedConfig.setCreateMapper(true);
        personalizedConfig.setUseLombok(true);
        personalizedConfig.setFieldRemoveUnderline(true);
//        personalizedConfig.setTablePrefixes(new String[] {"tb"});
//        personalizedConfig.setIncludeTables(new String[] {
//                "promotion_ad","promotion_space"
//        });
//    personalizedConfig.setExcludeTables(new String[] {
//        "mybatis_plus_demos"
//    });
        generator.setPersonalizedConfig(personalizedConfig);
        generator.execute();
    }
}

